package goescape

import "fmt"

type (
	eraseLineData struct {
		// Line content.
		Line,
		// All content.
		Data erase
	}

	erase struct {
		// Before the cursor.
		BeforeCursor,
		// After the cursor.
		AfterCursor,
		// All content.
		All Escape
	}

	scroll struct {
		// Down n lines.
		Down,
		// Up n lines.
		Up func(n uint16) Escape
	}

	content struct {
		// Return escape code for scrolling.
		Scroll scroll
		// Erase content.
		Erase eraseLineData
		// Return escape code for scrolling.
		Restore,
		// Save content.
		Save Escape
	}
)

// Return escape code to erase content.
func Content() content {
	return content{
		Scroll: scroll{
			Down: func(n uint16) Escape {
				return Escape(fmt.Sprintf("\x1b[%dS", n))
			},
			Up: func(n uint16) Escape {
				return Escape(fmt.Sprintf("\x1b[%dT", n))
			},
		},
		Erase: eraseLineData{
			erase{
				BeforeCursor: "\x1b[0K",
				AfterCursor:  "\x1b[1K",
				All:          "\x1b[2K",
			},
			erase{
				BeforeCursor: "\x1b[0J",
				AfterCursor:  "\x1b[1J",
				All:          "\x1b[2J",
			},
		},
		Restore: "\x1b[?47l",
		Save:    "\x1b[?47h",
	}
}
